package com.dingup.homework.handler;


import com.alibaba.fastjson.JSON;
import com.dingup.homework.bean.DO.CorrectTeacher;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by liuhaoyu on 16/8/8.
 */
public class CorrectTeacherHandler extends BaseTypeHandler<CorrectTeacher> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, CorrectTeacher parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, JSON.toJSONString(parameter));
    }

    @Override
    public CorrectTeacher getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return JSON.parseObject(rs.getString(columnName), CorrectTeacher.class);
    }

    @Override
    public CorrectTeacher getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return JSON.parseObject(rs.getString(columnIndex), CorrectTeacher.class);
    }

    @Override
    public CorrectTeacher getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return JSON.parseObject(cs.getString(columnIndex), CorrectTeacher.class);
    }
}
